package com.wannengbang.storemobile.merchant.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.makeramen.roundedimageview.RoundedImageView;
import com.wannengbang.storemobile.R;
import com.wannengbang.storemobile.bean.StoreListBean;
import com.wannengbang.storemobile.utils.GlideUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 */
public class MerchantStoreListAdapter extends RecyclerView.Adapter<MerchantStoreListAdapter.ViewHolder> {

    private OnCallBackListener onCallBackListener;
    private List<StoreListBean.DataBean.ItemListBean> listsBeans;
    private Context context;

    public MerchantStoreListAdapter(List<StoreListBean.DataBean.ItemListBean> listsBeans) {
        this.listsBeans = listsBeans;
    }

    public void setOnCallBackListener(OnCallBackListener onCallBackListener) {
        this.onCallBackListener = onCallBackListener;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_merchant_store_list, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        StoreListBean.DataBean.ItemListBean dataBean = listsBeans.get(position);
        holder.tvMerchantName.setText(dataBean.getName());
        if (dataBean.getPhoto_list() != null && dataBean.getPhoto_list().size() > 0) {
            for (StoreListBean.DataBean.ItemListBean.PhotoListBean photoListBean : dataBean.getPhoto_list()) {
                if ("door_pic".equals(photoListBean.getPhoto_type())) {
                    GlideUtils.loadImage(context, holder.ivPhoto, photoListBean.getPhoto_path());
                    break;
                }
            }
        } else {
            holder.ivPhoto.setImageResource(R.mipmap.ic_no_priture);
        }
//        if (dataBean.getPay_channel_status() == 0) {
//            holder.tvStatus.setText("未提交商户资料");
//        } else if (dataBean.getPay_channel_status() == 1 || dataBean.getPay_channel_status() == 2 || dataBean.getPay_channel_status() == 5) {
//            holder.tvStatus.setText("已提交资料，请等待审核");
//        } else if (dataBean.getPay_channel_status() == 3) {
//            holder.tvStatus.setText("已审核成功，可以正常收银");
//        } else if (dataBean.getPay_channel_status() == 4) {
//            holder.tvStatus.setText("审核未通过");
//        }
        holder.tvAddress.setText(dataBean.getAddress());

    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_photo)
        RoundedImageView ivPhoto;
        @BindView(R.id.tv_merchant_name)
        TextView tvMerchantName;
        @BindView(R.id.tv_address)
        TextView tvAddress;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface OnCallBackListener {
        void onCallBack(int type, int position);
    }
}
